import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
//引入svg需要用到的插件
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
//引入mock
import { viteMockServe } from "vite-plugin-mock";

export default defineConfig(({ command }) => {
  return {
    plugins: [
      vue(),
      //配置svg矢量图
      createSvgIconsPlugin({
        iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
        symbolId: "icon-[dir]-[name]",
      }),
      viteMockServe({
        // default
        mockPath: 'mock',
        localEnabled: command === 'serve',
      }),
    ],
    resolve: {
      alias: {
        "@": "/src", // 注意，这里不需要使用 path.resolve，因为 Vite 会自动处理
      },
    },
    css: {
      preprocessorOptions: {
        scss: {
          // javascriptEnabled: true,
          additionalData: `@import "./src/styles/variables.scss";`,
        },
      },
    },
  };
});
